<template>
  <div class="mod-api__notice">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-select v-model="state.dataForm.type" placeholder="请选择类型" value-key="" clearable filterable @change="">
          <el-option key="" label="全部" value=""> </el-option>
          <el-option :key="sd.value" :label="sd.label" :value="sd.value" v-for="sd in jjxcf"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select v-model="state.dataForm.isRead" placeholder="是否已读" value-key="" clearable filterable @change="">
          <el-option key="" label="全部" value=""> </el-option>
          <el-option key="1" label="已读" :value="true"> </el-option>
          <el-option key="2" label="未读" :value="false"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="state.getDataList()">搜索</el-button>
      </el-form-item>

      <el-form-item>
        <el-button v-if="state.hasPermission('api:notice:save')" type="primary"
          @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('api:notice:delete')" type="danger"
          @click="state.deleteHandle()">删除</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border
      @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <!-- <el-table-column prop="id" label="id" header-align="center" align="center"></el-table-column> -->
      <el-table-column prop="msg" label="通知消息" header-align="center" align="center"></el-table-column>
      <el-table-column prop="type" width="100" label="通知类型" header-align="center" align="center">

        <template #default="scope">
          {{ xczretr(scope.row.type) }}
        </template>

      </el-table-column>
      <el-table-column prop="userId" label="用户姓名" header-align="center" align="center">
        <template #default="scope">
          {{ kjxcxf(scope.row.userId) }}
        </template>
      </el-table-column>
      <!-- <el-table-column prop="isRead" label="是否阅读" header-align="center" align="center">
        <template #default="scope">
          {{ scope.row.isRead ? '是' : '否' }}
        </template>

      </el-table-column> -->
      <el-table-column prop="noticeTime" label="通知时间" header-align="center" align="center"></el-table-column>
      <el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="state.hasPermission('api:notice:update')" type="primary" link
            @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="primary" link @click="state.deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit"
      :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle"
      @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update ref="addOrUpdateRef" @refreshDataList="state.getDataList">确定</add-or-update>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { reactive, ref, toRefs } from "vue";
import AddOrUpdate from "./notice-add-or-update.vue";
// import { xczretr } from "@/utils/utils"
import { dxget,zkjsd } from "@/utils/utils";
const xczxtrt = ref()
const view = reactive({
  deleteIsBatch: true,
  getDataListURL: "/api/notice/page",
  getDataListIsPage: true,
  exportURL: "/api/notice/export",
  deleteURL: "/api/notice"
});
const jjxcf = ref([])

const state = reactive({ ...useView(view), ...toRefs(view) });

const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
  addOrUpdateRef.value.init(id);
};
const kjxcxf = (data) => {
  try {
    return xczxtrt.value.filter(a => a.id == data)[0].payName
  } catch (e) {
    return '-'
  }
}
const jmkxcf = async () => {

  const { list } = await dxget('/api/user/page', {
    limit: 999
  })
  xczxtrt.value = list
}
jmkxcf()


const getsd = async () => {
  jjxcf.value = []
  const { list } = await zkjsd("1225813644059140097")
  list.map(a => {
    jjxcf.value.push({
      label: a.dictLabel,
      value: a.dictValue
    })
  })
}
getsd()
const xczretr = (data)=>{
 try{
  return jjxcf.value.filter(a=>a.value==data)[0].label
 }catch(e){
  return '-'
 }
}
</script>
